package com.jzr.Stu1;

import com.jzr.Stu.StudentData;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentTest {
    public static void main(String[] args) {
        ArrayList<StudentData> shuju = new ArrayList<>();
        rui:
        while (true) {
            System.out.println("--------欢迎来到学生管理系统 --------");
            System.out.println("--------欢迎来到学生管理系统 --------");
            System.out.println("1 添加学生");
            System.out.println("2 删除学生");
            System.out.println("3 修改学生");
            System.out.println("4 查看学生");
            System.out.println("5 退出");
            System.out.println("请输入您的选择：");

            Scanner sc = new Scanner(System.in);
            int choice = sc.nextInt();

            switch (choice) {
                case 1:
                    AddStudent(shuju);
                    break;
                case 2:
                    RemoveStudent(shuju);
                    break;
                case 3:
                    SetStudent(shuju);
                    break;
                case 4:
                    CheckStudent(shuju);
                    break;
                case 5:
                    break rui;
                default:
                    System.out.println("您的选择有误，请重新输入");
            }
        }
    }


    public static void AddStudent(ArrayList<StudentData> shuju) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生学号");
        String sid = sc.next();
        System.out.println("请输入学生姓名");
        String name = sc.next();
        System.out.println("请输入学生年龄");
        int age = sc.nextInt();
        System.out.println("请输入学生生日");
        int birth = sc.nextInt();
        StudentData stu = new StudentData(sid, name, age, birth);
        shuju.add(stu);

    }

    public static void RemoveStudent(ArrayList<StudentData> shuju) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你需要移走的用户学号");
        String sid = sc.next();
        shuju.remove(sid);
    }

    public static void SetStudent(ArrayList<StudentData> shuju) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入需要重新设置的用户学号");
        String set = sc.next();
        int index = getIndex(shuju, set);
        if (index != -1) shuju.remove(index);
        AddStudent(shuju);
        System.out.println("修改成功");
    }

    public static int getIndex(ArrayList<StudentData> shuju, String set) {
        int c = -1;
        for (int i = 0; i < shuju.size(); i++) {
            StudentData a = shuju.get(i);
            String b = a.getSid();
            if (b == set) {
                c = i;
            }
        }
        return c;
    }

    public static void CheckStudent(ArrayList<StudentData> shuju) {
        System.out.println("学号/t姓名/t年龄/t生日");
        for (int i = 0; i < shuju.size(); i++) {
            StudentData a = shuju.get(i);
            System.out.println(a.getSid() + "    " + a.getName() + "    " + a.getAge() + "    " + a.getBirth());
        }
    }


}
